package com.fira.api.controller;

import java.util.List;

import com.fira.api.domain.dto.LoginDTO;
import com.fira.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.fira.common.annotation.Log;
import com.fira.common.enums.BusinessType;
import com.fira.edu.domain.EduMessageBoard;
import com.fira.edu.service.IEduMessageBoardService;
import com.fira.common.core.controller.BaseController;
import com.fira.common.core.domain.AjaxResult;
import com.fira.common.utils.poi.ExcelUtil;
import com.fira.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletRequest;

/**
 * 留言板Controller
 * 
 * @author tony
 * @date 2021-10-20
 */
@Api(value="留言板接口",tags={"留言板接口"})
@Controller
@RequestMapping("/api/board")
public class MessageBoardController extends ApiController
{
    @Autowired
    private IEduMessageBoardService eduMessageBoardService;

    /**
     * 查询留言板列表
     */
    @ApiOperation(value="查询留言板列表",tags={"查询留言板列表"},notes="")
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(@ApiParam("留言板列表查询入参") EduMessageBoard eduMessageBoard, HttpServletRequest request)
    {
        LoginDTO loginDTO = getLogin(request);
        String tenantId = loginDTO.getCurrentTenantId();
        if(StringUtils.isEmpty(tenantId)){
            return AjaxResult.error("请先登录");
        }
        eduMessageBoard.setTenantId(tenantId);
        startPage();
        List<EduMessageBoard> list = eduMessageBoardService.selectEduMessageBoardList(eduMessageBoard);
        return AjaxResult.success("查询成功",getDataTable(list));
    }

    /**
     * 新增保存留言板
     */
    @ApiOperation(value="新增留言板",tags={"新增留言板"},notes="")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@ApiParam(name = "新增留言入参") EduMessageBoard eduMessageBoard, HttpServletRequest request)
    {
        LoginDTO loginDTO = getLogin(request);
        String parentId = loginDTO.getParentId();
        if(StringUtils.isEmpty(parentId)){
            return AjaxResult.error("请先登录");
        }
        if(StringUtils.isEmpty(eduMessageBoard.getStudentId())){
            return AjaxResult.error("学生ID不能为空");
        }
        eduMessageBoard.setParentId(parentId);
        return toAjax(eduMessageBoardService.insertEduMessageBoard(eduMessageBoard));
    }

    /**
     * 修改保存留言板
     */
    @ApiOperation(value="查询留言板详情",tags={"查询留言板详情"},notes="")
    @PostMapping("/selectMessageById")
    @ResponseBody
    public AjaxResult selectMessageById(@ApiParam(name = "查询详情入参") @RequestParam String id, HttpServletRequest request)
    {
        LoginDTO loginDTO = getLogin(request);
        String parentId = loginDTO.getParentId();
        if(StringUtils.isEmpty(parentId)){
            return AjaxResult.error("请先登录");
        }
        if(StringUtils.isEmpty(id)){
            return AjaxResult.error("ID不能为空");
        }
        return AjaxResult.success("查询成功",eduMessageBoardService.selectEduMessageBoardById(id));
    }
}
